// ============================================================================================================================================
    //
    //
    //
    //
    // Noise模块
    //
    //
    //
    //
    // ============================================================================================================================================
#ifndef UNITY_SHADER_DT_NOISE_UTIL_INCLUDED  
#define UNITY_SHADER_DT_NOISE_UTIL_INCLUDED
     
    #define vec3 float3
    #define vec2 float2
    #define fract(a) frac(a)
    #define mix(a,b,t) lerp(a,b,t)     

    vec3 random_perlin( vec3 p ) {
        p = vec3(
            dot(p,vec3(127.1,311.7,69.5) ),
            dot(p,vec3(269.5,183.3,132.7)), 
            dot(p,vec3(247.3,108.5,96.5)) 
        );
        return -1.0 + 2.0 * fract(sin(p)*43758.5453123);
    }

    float noise(vec3 p)
    {
        vec3 i = floor(p); // 获取当前网格索引i
        vec3 f = fract(p); // 获取当前片元在网格内的相对位置
        float F1 = 1.0;
        // 遍历当前像素点相邻的9个网格特征点
        for (int j = -1; j <= 1; j++) {
            for (int k = -1; k <= 1; k++) {
                for (int l = -1; l <= 1; l++) {
                    vec3 neighbor = vec3(float(l), float(k),float(j));
                    vec3 p2 = random_perlin(i + neighbor);
                    float d = length(p2 + neighbor - f);
                    F1 = min(F1,d);
                }
            }
        }
        return F1;
    }    // 
    float noise_perlin (vec3 uvt) {
        vec3 i = floor(uvt);
        vec3 s = fract(uvt);
        // Smooth Interpolation
        vec3 u = smoothstep(0.0, 1.0, s);
        float a = dot(random_perlin(i),s);
        float b = dot(random_perlin(i + vec3(1, 0, 0)),s - vec3(1, 0, 0));
        float c = dot(random_perlin(i + vec3(0, 1, 0)),s - vec3(0, 1, 0));
        float d = dot(random_perlin(i + vec3(0, 0, 1)),s - vec3(0, 0, 1));
        float e = dot(random_perlin(i + vec3(1, 1, 0)),s - vec3(1, 1, 0));
        float f = dot(random_perlin(i + vec3(1, 0, 1)),s - vec3(1, 0, 1));
        float g = dot(random_perlin(i + vec3(0, 1, 1)),s - vec3(0, 1, 1));
        float h = dot(random_perlin(i + vec3(1, 1, 1)),s - vec3(1, 1, 1));
        float va = mix(mix( a, b, u.x), mix( c, e, u.x), u.y);
        float vb = mix(mix( d, f, u.x), mix( g, h, u.x), u.y);
        return mix(va, vb, u.z); 
    }
    //最总计算函数
    float noise_turbulence(vec2 uv,float time)
    {
        vec3 uvt = 0.0;
        uvt.xy = uv;
        uvt.z = time;
        float f = 0.0;
        float a = 1.0;
        uvt = /*平铺/大小*/vec3(4.0, 4.0, 1.0) * uvt;        
        for (int i = 0; i < /*细节*/10; i++) {
            f = f + a * noise_perlin(uvt);
            uvt = vec3(2.0, 2.0, 1.0) * uvt;
            a /= 2.0;
        }
        float result = abs(1.0 - f) * max(0.0, /*透度*/0.5);
        return pow(result,/*密度*/1.2);
    }
#endif //UNITY_SHADER_DT_NOISE_UTIL_INCLUDED